#include <iostream>
#include <string>
#include <list>
using namespace std;

class Person
{
public:
  Person(string n, int a)
  {
    name = n;
    age = a;
  }
  void print()
  {
    cout << "name: " << name << ", age: " << age << endl;
  }
  // make the attributes public to show that elements in                        
  // a list are copies                                                          
  string name;
  int age;
};

void print(list<Person>& li)
{
  typedef list<Person>::const_iterator CI;
  cout << "The number of items in the list: " << li.size() << endl;;
  for (CI iter = li.begin(); iter != li.end(); iter++)
    {
      Person p = * iter;
      p.print();
    }
  cout << endl << endl;
}

int main()
{
  list<Person> club;
  club.push_back(Person("Amy", 21));
  club.push_front(Person("Bob", 19));
  print(club);
  /*                                                                            
    The number of items in the list: 2                                          
    name: Bob, age: 19                                                          
    name: Amy, age: 21                                                          
  */
  Person p1("Charlie", 20);
  Person p2("Deborah", 22);
  club.push_front(p1);
  club.push_front(p2);
  print(club);
  /*                                                                            
    The number of items in the list: 4                                          
    name: Deborah, age: 22                                                      
    name: Charlie, age: 20                                                      
    name: Bob, age: 19                                                          
    name: Amy, age: 21                                                          
  */

  p1.name = "Sam";
  p1.age = 25;
  print(club);
  // Notice that Sam is not in the list                                         
  /*                                                                            
    The number of items in the list: 4                                          
    name: Deborah, age: 22                                                      
    name: Charlie, age: 20                                                      
    name: Bob, age: 19                                                          
    name: Amy, age: 21                                                          
  */

  club.pop_back();
  print(club);
  /*                                                                            
    The number of items in the list: 3                                          
    name: Deborah, age: 22                                                      
    name: Charlie, age: 20                                                      
    name: Bob, age: 19                                                          
  */
  return 0;
}

